<?$this->load->view('admin/header.tpl');?>
	<div id="wrap" class="lw clearfix ab">
		<?if($success):?><div class="success"><?=$success?></div><?endif?>
		<div class="form-error"><?=$error?></div>
		<div class="form-menu">
				<ul class="menu1 clearfix" id="menu1">
					<li class="on" id="li1_1"><a href="javascript:" onclick="change(1,1)">基本信息</a></li>
					<li class="off" id="li1_2"><a href="javascript:" onclick="change(2,1)">描述</a></li>
					<li class="off" id="li1_3"><a href="javascript:" onclick="change(3,1)">图片</a></li>
					<li class="off" id="li1_4"><a href="javascript:" onclick="change(4,1)">商品属性</a></li>
					<li class="go"><a href="/admin/production">返回</a></li>
				</ul>
		</div>
			<form action="<?=$action?>" method="post" class="form">

				<div id="con1_1">
					<div class="form-item clearfix">
						<div class="form-left">
							以下必填
						</div>
						<div class="form-right">
							<div class="form-right-label">
								<label for="name">商品名称</label>
							</div>
							<div class="form-right-text off">
								<input type="text" class="text w1" id="name" name="name" value="<?if($p){echo $p->name;}?>"/>
								<span class="form-border-right"></span>
							</div>
						</div>
					</div>
					<div class="form-item clearfix">
						<div class="form-left">
						</div>
						<div class="form-right">
							<div class="form-right-label">
								<label for="brand">商品品牌</label>
							</div>
							<div class="form-right-text off">
								<input type="text" class="text w1" id="brand" name="brand" value="<?if($p){echo $p->brand;}?>"/>
								<span class="form-border-right"></span>
							</div>
						</div>
					</div>
					<div class="form-item clearfix">
						<div class="form-left">
						</div>
						<div class="form-right">
							<div class="form-right-label">
								<label for="price">商品价格（单位：元）</label>
							</div>
							<div class="form-right-text off">
								<input type="text" class="text w1" id="price" name="price" value="<?if($p){echo $p->price;}?>"/>
								<span class="form-border-right"></span>
							</div>
						</div>
					</div>

					<div class="form-item clearfix">
						<div class="form-left">
							以下选填
						</div>
						<div class="form-right">
							<div class="form-right-label">
								<label for="short_name">简短名称</label>
							</div>
							<div class="form-right-text off">
								<input type="text" class="text w1" id="short_name" name="short_name" value="<?if($p){echo $p->short_name;}?>"/>
								<span class="form-border-right"></span>
							</div>
						</div>
					</div>

					<div class="form-item clearfix">
						<div class="form-left clearfix">
						</div>
						<div class="form-right">
							<div class="form-right-label">
								<label for="cat">商品分类</label>
							</div>
							<div class="form-right-text off">
								<input type="text" class="text w1" id="cat" name="cat" value="<?if($p){echo $p->cat;}?>" />
								<span class="form-border-right"></span>
							</div>
						</div>
					</div>

					<div class="form-item clearfix" style="border:none;">
						<div class="form-left clearfix">
						</div>
						<div class="form-right">
							<div class="form-right-label">
								<label for="photo">单击修改商品大图显示</label>
							</div>
							<div class="">
								<input type="hidden" id="image" value="<?if($p){echo $p->image;}?>" name="image">
								<a class="thumba" href="javascript:"><img onclick="image_upload('image', 'preview');" class="image" id="preview" alt="" src="<?=$preview?>"></a>
							</div>
						</div>
					</div>
					<div class="form-item clearfix">
						<div class="form-left clearfix">
						</div>
						<div class="form-right">
							<div class="form-right-label">
								<label for="photo">商品大图预览</label>
							</div>
							<div class="">
								<img id="big_image" alt="" src="<?if($p){echo HTTP_IMAGE . $p->image;}else {echo $preview;}?>">
							</div>
						</div>
					</div>
					

				</div>

			<div id="con1_2" class="hidden">
				
				<div class="form-item clearfix">
					<div class="form-left clearfix">
						
					</div>
					<div class="form-right">
						<div class="form-right-label">
							<label for="brif">简短描述</label>
						</div>
						<div class="">
							<textarea id="brif" name="brif" class="textarea"><?if($p){echo htmlspecialchars_decode(stripslashes($p->brif));}?></textarea>
						</div>
					</div>
				</div>

				<div class="form-item clearfix">
					<div class="form-left clearfix">
					</div>
					<div class="form-right">
						<div class="form-right-label">
							<label for="description">详细描述</label>
						</div>
						<div class="">
							<textarea id="description" name="description"><?if($p){echo htmlspecialchars_decode(stripslashes($p->description));}?></textarea>
						</div>
					</div>
				</div>
			</div>
			<div id="con1_3" class="hidden">
				<div class="form-item clearfix">
					<div class="form-left clearfix">
						点击图片可修改
					</div>
					<div class="form-center" style="padding-left:100px;">
						<div class="form-right-label">
							<label for="password">商品图</label>
						</div>
					</div>
					<div class="form-right">
						<div class="form-right-label">
							<label for="password">增加</label>
						</div>
						
					</div>
				</div>
				
				<?php $image_row = 0; $image_list = json_decode($p->production_image);?>
				<?if($image_list):?>
					<?foreach($image_list as $img):?>
						<div class="form-item clearfix" id="image_row<?php echo $image_row; ?>">
							<div class="form-left clearfix">
							</div>
							<div class="form-center">
								<div class="form-right-label">
								</div>
								
								<div class="form-right-image">
									<input type="hidden" name="production_image[<?php echo $image_row; ?>]" value="<?php echo $img; ?>" id="image<?php echo $image_row; ?>"  />
									<img src="<?php echo HTTP_IMAGE . $img; ?>" width="100px;" id="preview<?php echo $image_row; ?>" class="image" onclick="image_upload('image<?php echo $image_row; ?>', 'preview<?php echo $image_row; ?>');"/>
								</div>
							</div>
							<div class="" style="float:left;">
								<div class="form-right-label">
								</div>
								
								<div class="form-right-image">
									<a href="javascript:" class="del-image" onclick="$('#image_row<?php echo $image_row; ?>').remove();"></a>
								</div>
							</div>
						</div>
						<?$image_row++;?>
					<?endforeach?>
				<?endif;?>
				
				<div class="form-item clearfix" id="image-foot">
					<div class="form-left clearfix">
					</div>
					<div class="form-center">
						<div class="form-right-label">
						</div>
						
						<div class="form-right-image">
						</div>
					</div>
					<div class="" style="float:left;">
						<div class="form-right-label">
						</div>
						
						<div class="form-right-image">
							<a href="javascript:" class="add-image" onclick="addImage();"></a>
						</div>
					</div>
				</div>				



			</div>
			<div id="con1_4" class="hidden">
				<div class="form-item clearfix">
					<div class="form-left clearfix">
					</div>
					<div class="form-right">
						<div class="form-right-label">
							<label for="check_safe">安全检测</label>
						</div>
						<div class="">
							<textarea id="check_safe" name="check_safe"><?if($p){echo htmlspecialchars_decode(stripslashes($p->check_safe));}?></textarea>
						</div>
					</div>
				</div>

				<div class="form-item clearfix">
					<div class="form-left clearfix">
					</div>
					<div class="form-right">
						<div class="form-right-label">
							<label for="product">其他产品</label>
						</div>
						<div class="">
							<textarea id="product" name="product"><?if($p){echo htmlspecialchars_decode(stripslashes($p->product));}?></textarea>
						</div>
					</div>
				</div>
			</div>

			<div class="form-item clearfix">
				<div class="form-left clearfix">
				</div>
				<div class="form-right">
					<input type="submit" class="button"value="<?=$button?>" />
				</div>
			</div>
		</form>
	
	</div>
<script type="text/javascript" src="/www/ckeditor/ckeditor.js"></script>
<script type="text/javascript"><!--
CKEDITOR.replace('brif', {
	filebrowserBrowseUrl: '/common/filemanager',
	filebrowserImageBrowseUrl: '/common/filemanager',
	filebrowserFlashBrowseUrl: '/common/filemanager',
	filebrowserUploadUrl: '/common/filemanager',
	filebrowserImageUploadUrl: '/common/filemanager',
	filebrowserFlashUploadUrl: '/common/filemanager'
});
CKEDITOR.replace('description', {
	filebrowserBrowseUrl: '/common/filemanager',
	filebrowserImageBrowseUrl: '/common/filemanager',
	filebrowserFlashBrowseUrl: '/common/filemanager',
	filebrowserUploadUrl: '/common/filemanager',
	filebrowserImageUploadUrl: '/common/filemanager',
	filebrowserFlashUploadUrl: '/common/filemanager'
});
CKEDITOR.replace('check_safe', {
	filebrowserBrowseUrl: '/common/filemanager',
	filebrowserImageBrowseUrl: '/common/filemanager',
	filebrowserFlashBrowseUrl: '/common/filemanager',
	filebrowserUploadUrl: '/common/filemanager',
	filebrowserImageUploadUrl: '/common/filemanager',
	filebrowserFlashUploadUrl: '/common/filemanager'
});
CKEDITOR.replace('product', {
	filebrowserBrowseUrl: '/common/filemanager',
	filebrowserImageBrowseUrl: '/common/filemanager',
	filebrowserFlashBrowseUrl: '/common/filemanager',
	filebrowserUploadUrl: '/common/filemanager',
	filebrowserImageUploadUrl: '/common/filemanager',
	filebrowserFlashUploadUrl: '/common/filemanager'
});
//--></script>
<link rel="stylesheet" type="text/css" href="/www/js/jquery/ui/themes/ui-lightness/ui.all.css" />

<script type="text/javascript" src="/www/js/jquery/ui/ui.core.js"></script>
<script type="text/javascript" src="/www/js/jquery/ui/ui.draggable.js"></script>
<script type="text/javascript" src="/www/js/jquery/ui/ui.resizable.js"></script>
<script type="text/javascript" src="/www/js/jquery/ui/ui.dialog.js"></script>
<script type="text/javascript" src="/www/js/jquery/ui/external/bgiframe/jquery.bgiframe.js"></script>
<script type="text/javascript"><!--
function image_upload(field, preview) {
	$('#dialog').remove();
	
	$('#wrap').prepend('<div id="dialog" style="padding: 3px 0px 0px 0px;"><iframe src="/common/filemanager?field=' + encodeURIComponent(field) + '" style="padding:0; margin: 0; display: block; width: 100%; height: 100%;" frameborder="no" scrolling="auto"></iframe></div>');
	
	$('#dialog').dialog({
		title: '图片管理',
		close: function (event, ui) {
			if ($('#' + field).attr('value')) {
				$.ajax({
					url: '/common/filemanager/image',
					type: 'POST',
					data: 'image=' + encodeURIComponent($('#' + field).attr('value')),
					dataType: 'text',
					success: function(data) {
						$('#' + preview).replaceWith('<img src="' + data + '" alt="" id="' + preview + '" class="image" onclick="image_upload(\'' + field + '\', \'' + preview + '\');" />');

						if(field == 'image'){
							$("#big_image").attr('src',"<?=HTTP_IMAGE?>" + $("#image").val());
						}
					}
				});
			}
		},	
		bgiframe: false,
		width: 700,
		height: 400,
		resizable: false,
		modal: false
	});
};
//--></script>
<script type="text/javascript"><!--
var image_row = <?php echo $image_row; ?>;

function addImage() {

	html = '<div class="form-item clearfix" id="image_row'+image_row+'">';
	html += '<div class="form-left clearfix">';
	html += '</div>';
	html += '<div class="form-center">';
	html += '<div class="form-right-label">';
	html += '</div>';
	html += '<div class="form-right-image">';
		html += '<input type="hidden" name="production_image['+image_row+']" value="<?php echo HTTP_IMAGE?>/www/image/no_image.jpg" id="image'+image_row+'"  />';
		html += '<img src="/www/image/no_image.jpg" id="preview'+image_row+'" onclick="image_upload(\'image'+image_row+'\', \'preview'+image_row+'\');"/>';
	html += '</div>';
	html += '</div>';
	html += '<div class="" style="float:left;">';
		html += '<div class="form-right-label">';
		html += '</div>';
		html += '<div class="form-right-image">';
			html += '<a href="javascript:" class="del-image" onclick="$(\'#image_row'+image_row+'\').remove();"></a>';
		html += '</div>';
	html += '</div>';
	html +=  '</div>';
	
	$('#image-foot').before(html);
	
	image_row++;
}
//--></script>
<?$this->load->view('footer.tpl');?>